module.exports = function(sequelize, DataTypes) {
  var Payment = sequelize.define(
    'Payment',
    {
      amount: {
        type: DataTypes.DECIMAL(10, 2),
        defaultValue: 0,
        comment: 'Amount paid'
      }
    },
    {
      tableName: 'payments',
      paranoid: true,
      indexes: [
        {
          name: 'user_id_idx',
          fields: ['userId']
        },
        {
          name: 'payer_id_idx',
          fields: ['payerId']
        },
        {
          name: 'document_id_idx',
          fields: ['documentId']
        },
        {
          name: 'comment_id_idx',
          fields: ['commentId']
        }
      ],
      comments: 'Payment for Documents'
    }
  )

  Payment.associate = function(models) {
    this.belongsTo(models.User, {
      as: 'Buyer',
      foreignKey: 'userId',
      constraints: false
    })
    this.belongsTo(models.User, {
      as: 'Payer',
      foreignKey: 'payerId',
      constraints: false
    })
    this.belongsTo(models.Document, {
      as: 'Document',
      foreignKey: 'documentId',
      constraints: false
    })
    this.belongsTo(models.Comment, {
      as: 'Comment',
      foreignKey: 'commentId',
      constraints: false
    })
  }
  return Payment
}
